package kaka.controls
{
	import com.greensock.TweenLite;
	import com.greensock.plugins.MotionBlurPlugin;
	import com.greensock.plugins.TweenPlugin;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.controls.Alert;
	import mx.controls.Image;
	import mx.core.Application;
	import mx.events.FlexEvent;
	import mx.events.ToolTipEvent;
	
	public class TipsImage extends Image
	{
		//提示内容
		private var _tips:String;
		//提示出现方向
		private var _direction:String;
		//ToolTips
		private var toolTips:TooltipsPlus;
		//ToolTips的宽度
		private var _toolTipsWidth:Number;
		public function TipsImage()
		{
			super();
			buttonMode=true;
			useHandCursor=true;
			configEventListener();
		}
		private function configEventListener():void
		{
			addEventListener(ToolTipEvent.TOOL_TIP_CREATE,createToolTip);
			addEventListener(ToolTipEvent.TOOL_TIP_SHOW,showToolTips);
			addEventListener(ToolTipEvent.TOOL_TIP_HIDE,hideTooltipsPlus);
		}
		private function createToolTip(e:ToolTipEvent):void
		{
			toolTips=new TooltipsPlus();
			toolTips.addEventListener(FlexEvent.SHOW,showTooltipsPlus);
			toolTips.toolTipWidth=toolTipsWidth;
			toolTips.txtContent=_tips;
			e.toolTip=toolTips;
		}
		private var fromX:Number;
		private var fromY:Number;
		private var toX:Number;
		private var toY:Number;
		private function showToolTips(e:ToolTipEvent):void
		{
			var _point:Point;
			switch(_direction)
			{
				case "up":
					_point=new Point(this.x,this.y-e.toolTip.height-5);
					_point=this.parent.localToGlobal(_point); 
					fromX=_point.x;
					fromY=_point.y-e.toolTip.height+10;
					toX=_point.x;
					toY=_point.y;
					break;
				case "down":
					_point=new Point(this.x,this.y+this.height+5);
					_point=this.parent.localToGlobal(_point); 
					fromX=_point.x;
					fromY=_point.y+10;
					toX=_point.x;
					toY=_point.y;
					break;
				case "left":
					_point=new Point(this.x-this.width-5,this.y);
					_point=this.parent.localToGlobal(_point); 
					fromX=_point.x-10;
					fromY=_point.y;
					toX=_point.x;
					toY=_point.y;
					break;
				case "right":
					_point=new Point(this.x+this.width+5,this.y);
					_point=this.parent.localToGlobal(_point); 
					fromX=_point.x+10;
					fromY=_point.y;
					toX=_point.x;
					toY=_point.y;
					break;
				default:
					_point=new Point(this.x,this.y-e.toolTip.height-10);
					_point=this.parent.localToGlobal(_point); 
					fromX=_point.x;
					fromY=_point.y-e.toolTip.height+10;
					toX=_point.x;
					toY=_point.y;
			}
			e.toolTip.x=_point.x;
			e.toolTip.y=_point.y;
		}
		/**
		 * 显示ToolTips效果
		 **/
		private function showTooltipsPlus(e:FlexEvent):void
		{
			TweenPlugin.activate([MotionBlurPlugin]);
			TweenLite.from(toolTips,0.5,{x:fromX,y:fromY});
			TweenLite.to(toolTips,0.5,{x:toX,y:toY,motionBlur:{strength:2, quality:3}});
		}
		/**
		 * 隐藏ToolTips效果
		 **/
		private function hideTooltipsPlus(e:ToolTipEvent):void
		{
			
		}
		
		public function get direction():String
		{
			return _direction;
		}
		
		[Inspectable(defaultValue="up",enumeration="up,down,left,right")]
		public function set direction(value:String):void
		{
			_direction = value;
		}

		public function get tips():String
		{
			return _tips;
		}

		public function set tips(value:String):void
		{
			_tips = value;
		}

		public function get toolTipsWidth():Number
		{
			return _toolTipsWidth;
		}

		public function set toolTipsWidth(value:Number):void
		{
			_toolTipsWidth = value;
		}


	}
}